from django.db import models
from django.contrib.auth.models import AbstractUser

from stock.models import Stock
# Create your models here.


class MyUser(AbstractUser):
    cny_free = models.DecimalField(default=999999, verbose_name='可用金额', decimal_places=3, max_digits=10)
    cny_freezed = models.DecimalField(default=0, verbose_name='冻结金额', decimal_places=3, max_digits=10)

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name


class Position(models.Model):
    user = models.ForeignKey(MyUser,on_delete=models.CASCADE,related_name='user_position',verbose_name='用户')
    stock = models.ForeignKey(Stock,on_delete=models.CASCADE,related_name='stock_position',verbose_name='股票')
    num_free = models.DecimalField(default=0,verbose_name='可交易股票',decimal_places=3,max_digits=10)
    num_freezed = models.DecimalField(default=0,verbose_name='冻结股票',decimal_places=3,max_digits=10)

    def __str__(self):
        return "用户" + self.user.username + "持有" + str(self.num_free) + self.stock.name


